﻿define(['config'],
    function(config) {

        function configureMetadataStore(metadataStore) {
            metadataStore.registerEntityTypeCtor(
                'Car', function () { this.isPartial = false; }, carInitializer);
            metadataStore.registerEntityTypeCtor(
                'Image', function () { this.isPartial = false; }, imageInitializer);
        }

        //#Internal methods

        function carInitializer(car) {
            car.priceFormated = ko.computed(function () {
                var price = car.price();
                var priceFormated = accounting.formatMoney(price, "₱ ", 2, ",", ".");
                return priceFormated;
            });
        }
        
        function imageInitializer(image) {
            image.imageName = ko.computed(function () {
                var imageFileName = config.imageFileNamePrefix + image.car().name() + '/' + image.fileName();
                return imageFileName;
            });
            image.imagePath = ko.computed(function () {
                var imageFilePath = config.imageFileNamePrefix + image.car().name();
                return imageFilePath;
            });

        }


        var model = {
            configureMetadataStore: configureMetadataStore
        };

        return model;

    });